home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / WarpQuake / Src / in_amiga.c < prev    next >
C/C++ Source or Header  |  2000-05-22  |  5KB  |  214 lines

  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20. // in_amiga.c -- amiga input
  21.  
  22. #include <exec/exec.h>
  23. #include <intuition/intuition.h>
  24. #include <utility/tagitem.h>
  25. #include <libraries/lowlevel.h>
  26. #include <powerup/ppcproto/lowlevel.h>
  27. #include <powerup/ppcproto/exec.h>
  28.  
  29. #include "quakedef.h"
  30.  
  31. cvar_t m_filter = {"m_filter", "1"};
  32.  
  33. static qboolean using_mouse = false;
  34. static qboolean using_joypad = false;
  35. short int last_mouse[2] = {0, 0};
  36. extern qboolean mousemove;
  37.  
  38. struct Library *LowLevelBase = NULL;
  39.  
  40. void IN_MouseMove (usercmd_t *cmd);
  41. void Init_Joypad (void);
  42. void Read_Joypad (void);
  43.  
  44. void Read_Joypad (void)
  45. {
  46.     ULONG joypos;
  47.  
  48.     joypos = ReadJoyPort(1);
  49.  
  50.     if (joypos & JPF_JOY_LEFT)
  51.         Key_Event (K_AUX1, true);
  52.     else
  53.         Key_Event (K_AUX1, false);
  54.  
  55.     if (joypos & JPF_JOY_RIGHT)
  56.         Key_Event (K_AUX2, true);
  57.     else
  58.         Key_Event (K_AUX2, false);
  59.  
  60.     if (joypos & JPF_JOY_UP)
  61.         Key_Event (K_AUX3, true);
  62.     else
  63.         Key_Event (K_AUX3, false);
  64.  
  65.     if (joypos & JPF_JOY_DOWN)
  66.         Key_Event (K_AUX4, true);
  67.     else
  68.         Key_Event (K_AUX4, false);
  69.  
  70.     if (joypos & JPF_BUTTON_RED)
  71.         Key_Event (K_AUX5, true);
  72.     else
  73.         Key_Event (K_AUX5, false);
  74.  
  75.     if (joypos & JPF_BUTTON_GREEN)
  76.         Key_Event (K_AUX6, true);
  77.     else
  78.         Key_Event (K_AUX6, false);
  79.  
  80.     if (joypos & JPF_BUTTON_YELLOW)
  81.         Key_Event (K_AUX7, true);
  82.     else
  83.         Key_Event (K_AUX7, false);
  84.  
  85.     if (joypos & JPF_BUTTON_BLUE)
  86.         Key_Event (K_AUX8, true);
  87.     else
  88.         Key_Event (K_AUX8, false);
  89.  
  90.     if (joypos & JPF_BUTTON_PLAY)
  91.         Key_Event (K_AUX9, true);
  92.     else
  93.         Key_Event (K_AUX9, false);
  94.  
  95.     if (joypos & JPF_BUTTON_FORWARD)
  96.         Key_Event (K_AUX10, true);
  97.     else
  98.         Key_Event (K_AUX10, false);
  99.  
  100.     if (joypos & JPF_BUTTON_REVERSE)
  101.         Key_Event (K_AUX11 ,true);
  102.     else
  103.         Key_Event (K_AUX11, false);
  104. }
  105.  
  106. void Init_Joypad (void)
  107. {
  108.     struct TagItem ti_attrs[] = {{SJA_Type, SJA_TYPE_GAMECTLR}, {TAG_END, 0}};
  109.  
  110.     LowLevelBase = OpenLibrary ("lowlevel.library", 0);
  111.     if (LowLevelBase)
  112.     {
  113.         Con_Printf ("Joypad enabled\n");
  114.         if (SetJoyPortAttrsA (1, &ti_attrs))
  115.             using_joypad = true;
  116.         else
  117.             Sys_Error ("SetJoyPortAttrsA() failed\n");
  118.     }
  119.     else
  120.     {
  121.         Con_Printf ("Can't open lowlevel.library\n");
  122.         using_joypad = false;
  123.     }
  124. }
  125.  
  126. void IN_Init (void)
  127. {
  128.   using_mouse = COM_CheckParm ("-mouse");
  129.   if (using_mouse)
  130.     Cvar_RegisterVariable (&m_filter);
  131.  
  132.     using_joypad = COM_CheckParm ("-joypad");
  133.     if (using_joypad)
  134.         Init_Joypad();
  135. }
  136.  
  137. void IN_Shutdown (void)
  138. {
  139.     struct TagItem ti_attrs[] = {{SJA_Type, SJA_TYPE_AUTOSENSE}, {TAG_END, 0}};
  140.  
  141.     if (using_joypad)
  142.         SetJoyPortAttrsA(1, &ti_attrs);
  143.  
  144.     if (LowLevelBase != NULL)
  145.     {
  146.         CloseLibrary (LowLevelBase);
  147.         LowLevelBase = NULL;
  148.     }
  149. }
  150.  
  151. void IN_Commands (void)
  152. {
  153.     if (using_joypad)
  154.         Read_Joypad();
  155. }
  156.  
  157. void IN_Move (usercmd_t *cmd)
  158. {
  159.     if (using_mouse)
  160.         IN_MouseMove (cmd);
  161. }
  162.  
  163. void IN_MouseMove(usercmd_t *cmd)
  164. {
  165.     short int mx, my;
  166.   double mouse_x, mouse_y;
  167.   static int old_mouse_x = 0, old_mouse_y = 0;
  168.  
  169.     if (mousemove == false)
  170.         return;
  171.  
  172.     mousemove = false;
  173.  
  174.     mx = (last_mouse[0] >> 1) << 3;
  175.   my = (last_mouse[1] >> 1) << 3;
  176.  
  177.     
  178.   if (m_filter.value) {
  179.     mouse_x = 0.5 * (mx + old_mouse_x);
  180.     mouse_y = 0.5 * (my + old_mouse_y);
  181.   } else {
  182.     mouse_x = (double)mx;
  183.     mouse_y = (double)my;
  184.   }
  185.  
  186.   mouse_x *= sensitivity.value;
  187.   mouse_y *= sensitivity.value;
  188.  
  189.   old_mouse_x = mx;
  190.   old_mouse_y = my;
  191.  
  192.   /* add mouse X/Y movement to cmd */
  193.   if ((in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1)))
  194.     cmd->sidemove += m_side.value * mouse_x;
  195.   else
  196.     cl.viewangles[YAW] -= m_yaw.value * mouse_x;
  197.  
  198.   if (in_mlook.state & 1)
  199.     V_StopPitchDrift ();
  200.  
  201.   if ((in_mlook.state & 1) && !(in_strafe.state & 1)) {
  202.     cl.viewangles[PITCH] += m_pitch.value * mouse_y;
  203.     if (cl.viewangles[PITCH] > 80)
  204.       cl.viewangles[PITCH] = 80;
  205.     if (cl.viewangles[PITCH] < -70)
  206.       cl.viewangles[PITCH] = -70;
  207.   } else {
  208.     if ((in_strafe.state & 1) && noclip_anglehack)
  209.       cmd->upmove -= m_forward.value * mouse_y;
  210.     else
  211.       cmd->forwardmove -= m_forward.value * mouse_y;
  212.   }
  213. }
  214.